package com.srxz.personnelsystem.system.controller;

import com.srxz.personnelsystem.system.mapper.dto.PositionDTO;
import com.srxz.personnelsystem.system.service.PositionService;
import com.srxz.personnelsystem.util.BackMessage;
import com.srxz.personnelsystem.util.PageParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: PositionController
 * @author: wgchao
 * @createTime: 2019/1/24 10:49 AM
 * @Description: TODO
 */
@RestController
@RequestMapping("/personnel/sys")
public class PositionController {

    @Autowired
    private PositionService positionService;

    @PostMapping("/position")
    public BackMessage save(@RequestBody PositionDTO positionDTO){
        if(StringUtils.isEmpty(positionDTO.getName())){
            return BackMessage.error("职位名称缺失");
        }
        return positionService.save(positionDTO);
    }

    @DeleteMapping("/position")
    public BackMessage delete(@RequestBody PositionDTO positionDTO){
        if(StringUtils.isEmpty(positionDTO.getId())){
            return BackMessage.error("主键缺失");
        }
        return positionService.delete(positionDTO);
    }

    @PutMapping("/position")
    public BackMessage update(@RequestBody PositionDTO positionDTO){
        if(StringUtils.isEmpty(positionDTO.getId())){
            return BackMessage.error("主键缺失");
        }
        return positionService.update(positionDTO);
    }

    @GetMapping("/position")
    public BackMessage search(String id){
        if(StringUtils.isEmpty(id)){
            return BackMessage.error("主键缺失");
        }
        return positionService.search(id);
    }

    //TODO 按照层级关系查询



    @PostMapping("/positionofpage")
    public BackMessage searchToPage(@RequestBody PageParam pageParam){
        return positionService.searchToPage(pageParam);
    }

    @DeleteMapping("/positionlist")
    public BackMessage deleteList(@RequestBody List<PositionDTO> positionDTOS){
        return positionService.deleteList(positionDTOS);
    }

    @GetMapping("/departnouse")
    public BackMessage searchAllOfNoUse(String depatmentId){
        return positionService.searchAllOfNoUse(depatmentId);
    }
}
